package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main()  {
	
	str := "! hello,wor,ld汉字 ! "
	fmt.Println(len(str)) //汉字占3个字节

	arr := []rune(str)   //遍历字符串
	for i:=0;i<len(arr);i++ {
		fmt.Printf("%c\n",arr[i])
	}

	n,err := strconv.Atoi("123")  //字符串转整数
	if err == nil {
		fmt.Println(n)
	}

	str1 := strconv.Itoa(123)  //整数转字符串
	fmt.Printf("%q\n",str1)

	bytes := []byte(str)  //字符串转byte数组
	fmt.Printf("%v\n",bytes)
	
	str2 := string(bytes)  //byte数组转字符串
	fmt.Println(str2)

	str3 := strconv.FormatInt(123,2)  //十进制转2进制 8，16进制将2修改即可
	fmt.Println(str3)

	fmt.Println(strings.Contains("seafood","food"))   //返回是否含有food

	fmt.Println(strings.Count("eesscchee","e"))   //返回含有多少个e

	fmt.Println("abc"=="ABC")   //字符串比较区分大小写
	fmt.Println(strings.EqualFold("abc","ABC"))   //字符串比较不区分大小写

	fmt.Println(strings.Index("abecdea","e"))  //返回e第一次出现的下标
	fmt.Println(strings.LastIndex("abecdea","e"))  //返回e最后一次出现的下标

	fmt.Println(strings.Replace("go go hello","go","替换",1)) //用替换替换字符串的go,1表示只替换一个，-1表示全部替换

	arr2 := strings.Split(str,",")  //分割字符串
	for i:=0;i<len(arr2);i++ {
		fmt.Println(arr2[i])
	}

	fmt.Println(strings.ToLower("Ab"))  //转小写
	fmt.Println(strings.ToUpper("Ab"))  //转大写

	fmt.Printf("%q\n",strings.TrimSpace("  test  "))  //取出字符串两边的空格

	fmt.Printf("%q\n",strings.Trim(str," !"))   //去除字符串两边的空格和！

	fmt.Printf("%q\n",strings.TrimLeft(str," !"))  //左边
	fmt.Printf("%q\n",strings.TrimRight(str," !"))  //右边

	fmt.Println(strings.HasPrefix("ftp://192","ftp"))  //判断前缀
	fmt.Println(strings.HasSuffix("test.jpg",".jpg"))  //判断后缀

}
